package com.linjiang.service;


import com.linjiang.spring.*;

@Component(name = "service")//bean 注解，并指定bean名称
@Scope("prototype")//声明bean的作用域，即该bean是单例还是原型
public class MyService implements BeanNameAware, InitializingBean {

    @Autowired
    private OtherService otherService;

    @Value("value")
    private String value;

    private String beanName;

    public void setName(String name) {
        this.beanName = name;
    }
    public MyService() {
    }

    public void doSomeThing(){
        System.out.println("调用方法======");
        System.out.println("OtherService======>"+otherService);
        System.out.println("beanName======>"+beanName);
        System.out.println("value======>"+value);
    }

    /**
     * bean在创建时，得到bean的名称
     * @param name
     */
    @Override
    public void setBeanName(String name) {
        this.beanName = name;
    }

    /**
     * 此方法允许 Bean 实例在设置所有 Bean 属性后执行其整体配置和最终初始化的验证。
     * @throws Exception
     */
    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("service开始初始化=====>");
    }
}
